import os, fnmatch, re, codecs

def main():
#Input top level directory absolute path with your tomboy notes
#Windows paths need to be like in linux "/" or unspecialized with double "\"
  ROOT = "D:\\tomboys"
  PATTERN = "*.note" 
  filepaths = []
  listOfnotes=[]
#Get all paths recursively
  for dirpath, dirnames, filenames in os.walk (ROOT): 
    filepaths.extend ( 
    os.path.join (dirpath, f) for f in fnmatch.filter (filenames, PATTERN) 
    )
#Pattern for title
  p=re.compile(r'<title>(.*)</title>', re.S)
#Read all titles
  for i in filepaths:
    f = codecs.open(i, 'rU', 'UTF-8')
    text=f.read()
    match = p.search(text)
    title=match.group(1)
    listOfnotes.append(title)
  f.close()
#Sort list of titles
  l=sorted(listOfnotes)
#Delete duplicates in a list (a case when local directory of Tomboy was synced from nix and win versions)
  s = set(); n = 0
  for x in l:
    if x not in s: s.add(x); l[n] = x; n += 1
  del l[n:]  
#Write list in a file to the same dir
  fin=codecs.open(ROOT+'\\results.txt', 'wU', 'UTF-8')
  for i in l:
    fin.write(i+'\n')
  fin.close()  
# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
  main()